package model.dao;

import java.sql.SQLException;
import java.util.List;

import model.domain.UserInfoBean;
import model.util.DBUtil;

import com.ibatis.sqlmap.client.SqlMapClient;

public class UserInfoDao {
	private static SqlMapClient sqlMapper = DBUtil.getParser();
	// Create
	public static void insertUserInfo(UserInfoBean bean) throws Exception {
		try {
			System.out.println(bean);
			sqlMapper.update("userInfo.insertUserInfo", bean);
			System.out.println(1);
		} catch (SQLException e) {
			throw new Exception("insertUserInfo error");
		}
	}

	// Read
	public static UserInfoBean readUserInfo(String userId) throws Exception {
		try {
			return (UserInfoBean) DBUtil.getParser().queryForObject(
					"userInfo.readUserInfo", userId);
		} catch (SQLException e) {
			throw new Exception("readUserInfo error");
		}
	}

	@SuppressWarnings("unchecked")
	public static List<UserInfoBean> readUserInfo() throws Exception {
		try {
			return (List<UserInfoBean>) DBUtil.getParser().queryForList(
					"userInfo.readAllUserInfo");
		} catch (SQLException e) {
			throw new Exception("readAllUserInfo error");
		}
	}

	// Update
	public static void updateUserInfo(UserInfoBean bean) throws Exception {
		try {
			DBUtil.getParser().update("userInfo.updateUserInfo", bean);
		} catch (SQLException e) {
			throw new Exception("updateUserInfo error");
		}
	}

	// Delete
	public static void deleteUserInfo(UserInfoBean bean) throws Exception {
		try {
			DBUtil.getParser().update("userInfo.updateUserInfo", bean);
		} catch (SQLException e) {
			throw new Exception("deleteUserInfo error");
		}
	}
	
	//create user 개인 table생성
	public static void createUserTable(String userId) throws Exception {
		try{
			DBUtil.getParser().update("userInfo.createUserTable", userId);
		}catch(SQLException e){
			e.printStackTrace();
			throw new Exception("createUserTable error");
		}
	}
}
